package com.whfc.ms.api.base.service.impl;

import com.whfc.common.file.FileHandler;
import com.whfc.common.file.FilePathConfig;
import com.whfc.common.result.ListData;
import com.whfc.common.result.PageData;
import com.whfc.common.util.RandomUtil;
import com.whfc.entity.dto.UploadImgDTO;
import com.whfc.fuum.dto.AppProjectDTO;
import com.whfc.fuum.dto.AppProjectDetailDTO;
import com.whfc.fuum.entity.SysUser;
import com.whfc.fuum.param.AppProjectParam;
import com.whfc.fuum.service.AppProjectService;
import com.whfc.ms.api.base.service.MsAppProjectService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.InputStream;

/**
 * @author qzexing
 * @version 1.0
 * @date 2020-12-11 09:29
 */
@Service
public class MsAppProjectServiceImpl implements MsAppProjectService {

    /**
     * 项目图片路径
     */
    private String projectImgPath = "project/img";

    @DubboReference(interfaceClass = AppProjectService.class, version = "1.0.0")
    private AppProjectService appProjectService;

    @Autowired
    private FileHandler fileHandler;

    @Autowired
    private FilePathConfig filePathConfig;


    @Override
    public PageData<AppProjectDTO> list(SysUser user, Integer pageNum, Integer pageSize, String keyword) {
        return appProjectService.list(user, pageNum, pageSize, keyword);
    }

    @Override
    public ListData<AppProjectDTO> list(SysUser user) {
        return appProjectService.list(user);
    }

    @Override
    public AppProjectDetailDTO detail(Integer deptId) {
        return appProjectService.detail(deptId);
    }

    @Override
    public void edit(AppProjectParam appProjectParam) {
        appProjectService.edit(appProjectParam);
    }

    @Override
    public UploadImgDTO uploadImg(InputStream fileInputStream) {
        UploadImgDTO uploadImgDTO = new UploadImgDTO();
        String fileName = RandomUtil.getRandomFileName() + ".png";
        String ossKey = filePathConfig.getFilePath(projectImgPath, fileName);
        String upload = fileHandler.upload(ossKey, fileInputStream);
        uploadImgDTO.setUrl(upload);
        return uploadImgDTO;
    }
}
